package cn.seocoo.platform.web.controller.advertisement;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.seocoo.platform.common.annotation.Log;
import cn.seocoo.platform.common.enums.BusinessType;
import cn.seocoo.platform.advertisement.domain.Advertisement;
import cn.seocoo.platform.advertisement.service.IAdvertisementService;
import cn.seocoo.platform.common.core.controller.BaseController;
import cn.seocoo.platform.common.core.page.TableDataInfo;
import cn.seocoo.platform.common.core.domain.AjaxResult;
import cn.seocoo.platform.common.utils.poi.ExcelUtil;

/**
 * 广告 信息操作处理
 * 
 * @author wujian
 * @date 2020-01-05
 */
@Controller
@RequestMapping("/advertisement/advertisement")
public class AdvertisementController extends BaseController
{
    private String prefix = "advertisement/advertisement";
	
	@Autowired
	private IAdvertisementService advertisementService;
	
	@RequiresPermissions("advertisement:advertisement:view")
	@GetMapping()
	public String advertisement()
	{
	    return prefix + "/advertisement";
	}
	
	/**
	 * 查询广告列表
	 */
	@RequiresPermissions("advertisement:advertisement:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Advertisement advertisement)
	{
		startPage();
        List<Advertisement> list = advertisementService.selectAdvertisementList(advertisement);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出广告列表
	 */
	@RequiresPermissions("advertisement:advertisement:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Advertisement advertisement)
    {
    	List<Advertisement> list = advertisementService.selectAdvertisementList(advertisement);
        ExcelUtil<Advertisement> util = new ExcelUtil<Advertisement>(Advertisement.class);
        return util.exportExcel(list, "advertisement");
    }
	
	/**
	 * 新增广告
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存广告
	 */
	@RequiresPermissions("advertisement:advertisement:add")
	@Log(title = "广告", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Advertisement advertisement)
	{		
		return toAjax(advertisementService.insertAdvertisement(advertisement));
	}

	/**
	 * 修改广告
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Advertisement advertisement = advertisementService.selectAdvertisementById(id);
		mmap.put("advertisement", advertisement);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存广告
	 */
	@RequiresPermissions("advertisement:advertisement:edit")
	@Log(title = "广告", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Advertisement advertisement)
	{		
		return toAjax(advertisementService.updateAdvertisement(advertisement));
	}
	
	/**
	 * 删除广告
	 */
	@RequiresPermissions("advertisement:advertisement:remove")
	@Log(title = "广告", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(advertisementService.deleteAdvertisementByIds(ids));
	}
	
}
